<!DOCTYPE html>
<html lang="zh-CN" style="height: 100%">
<head>
    <meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">

<div id="container" style="height: 100%"></div>

<script type="text/javascript" src="../echarts.js"></script>
<script src="../../js/axios.min.js"></script>

<script>
    axios.get('http://localhost:8080/engineer/getMyInfo', {
        withCredentials: true
    }).then(function(res) {
        originalData = res.data.data;
        var engId = originalData.engineerId;
        console.log(originalData.engineerId);

        axios.get('http://localhost:8080/order/getOrderCount/' + engId, {
            withCredentials: true
        }).then(function(res) {
            originalData = res.data.data;
            console.log(originalData);

            var count1 = originalData.status1Orders;
            var count2 = originalData.status2Orders;
            var count3 = originalData.status3Orders;
            var count4 = originalData.status4Orders;
            var dom = document.getElementById('container');
            var myChart = echarts.init(dom, null, {
                renderer: 'canvas',
                useDirtyRect: false
            });

            var option = {
                title: {
                    text: '订单状态统计',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },

                series: [
                    {
                        name: '订单状态',
                        type: 'pie',
                        radius: '50%',
                        data: [
                            { value: count1, name: '已接单' },
                            { value: count2, name: '待审核' },
                            { value: count3, name: '已完结' },
                            { value: count4, name: '订单被退回' },
                        ],
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            if (option && typeof option === 'object') {
                myChart.setOption(option);
            }

            window.addEventListener('resize', myChart.resize);
        })
    }).catch(function(error) {
        console.log(document.cookie)
        // 请求失败的处理逻辑
        console.error(error);
    });
</script>
</body>
</html>
